package com.ydl.partitionscheduler.config;

import com.ydl.partitionscheduler.enums.DatabaseType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "spring.datasource")
@Data
public class DataSourceConfig {
    private String url;
    private String username;
    private String password;
    private String driverClassName;

    /**
     * 识别数据库类型
     */
    @Bean
    public DatabaseType databaseType() {
        if (url.contains("mysql")) {
            return DatabaseType.MYSQL;
        } else if (url.contains("oracle")) {
            return DatabaseType.ORACLE;
        } else if (url.contains("postgresql")) {
            return DatabaseType.POSTGRESQL;
        }
        throw new IllegalArgumentException("不支持的数据库类型: " + url);
    }
}
